from django.db import models


# Create your models here.

class Student(models.Model):
    name = models.CharField(max_length=10)
    age = models.IntegerField(blank=False)


class Author(models.Model):
    author_name = models.CharField("作者", max_length=10)

    def __str__(self):
        return self.author_name


class Tag(models.Model):
    tag_name = models.CharField("标签", max_length=10)

    def __str__(self):
        return self.tag_name


class Category(models.Model):
    category_name = models.CharField("分类", max_length=10)

    def __str__(self):
        return self.category_name


class Post(models.Model):
    from DjangoUeditor.models import UEditorField
    name = models.CharField("文章", max_length=10)
    concent = UEditorField(width=1100, height=600,imagePath="advance_view/static/img/Post")
    author_name = models.ForeignKey(Author)
    tag = models.ManyToManyField(Tag)
    category = models.ForeignKey(Category)
    photo = models.ImageField(upload_to="Post/")  # 保存图片的路径

    def __str__(self):
        return self.name

    def myauthor(self):
        return self.author_name

    myauthor.short_description = "作者"

    def mycategory(self):
        return self.category

    mycategory.short_description = "分类"

    def mytag(self):
        return "/".join([i.tag_name for i in self.tag.all()])

    mytag.short_description = "标签"
